package com.test.restruant;

import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@SpringBootApplication
@EnableDubbo//开启dubbo
//注解必须加，除非dao接口和mapper的xml文件在一个包下，并且文件名一样，
//@MapperScan("com.test.restruant.dao")
public class ServiceApplication {
//    @Autowired
//    private RedisTemplate<String, String> redisTemplate;

    public static void main(String[] args) {
        SpringApplication.run(ServiceApplication.class);
    }
    //解决中文乱码
    @Bean
    public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
        StringRedisTemplate template = new StringRedisTemplate();
        template.setConnectionFactory(factory);
// key序列化
        template.setKeySerializer(new StringRedisSerializer());
        //val实例化
        template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
        return template;
    }
}
